﻿using System.Collections.ObjectModel;
using System.Drawing;

namespace SolarWinds.Logic
{
    public class CargoBay : Collection<Cargo>
    {
        private Size mSize = new Size(16, 16);

        public Size Size
        {
            get { return mSize; }
            set { mSize = value; }
        }

        public int TotalSlots
        {
            get { return mSize.Width * mSize.Height; }
        }

        public int FreeSlots
        {
            get 
            { 
                int usedSlots = 0;

                foreach (Cargo c in this)
                {   
                    usedSlots += c.Slots;
                }

                return (TotalSlots - usedSlots); 
            }
        }


        protected override void InsertItem(int index, Cargo item)
        {
            if (item == null ||
                IndexOf(item) != -1 ||
                FreeSlots < item.Slots)
            {
                return;
            }

            base.InsertItem(index, item);
        }
    }
}